package com.sunlands.zlcx.usercenter.domain.share;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;

@Data
@Entity(name = "tz_user_share_info")
@NoArgsConstructor
@AllArgsConstructor
@Builder
@DynamicUpdate
@DynamicInsert
public class UserShareInfoDO {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @ApiModelProperty(value = "学习id")
    private Long learnId;
    @ApiModelProperty(value = "用户id")
    private Long userId;
    @ApiModelProperty(value = "分享内容")
    private String shareContent;
    @ApiModelProperty(value = "状态")
    private Integer status;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;

    public enum Status {

        LEARNING("learning","正在学习中", 1),
        LEARN_OVER("learn_over", "学习结束", 2);

        Status(String info, String tips, int code) {
            this.info = info;
            this.tips = tips;
            this.code = code;
        }

        private String info;
        private String tips;
        private int code;

        public static Status getLearningStatus(int code) {
            for (Status field : Status.values()) {
                if (code == field.getCode()) {
                    return field;
                }
            }
            return null;
        }

        public int getCode() {
            return code;
        }
    }

}
